You decided to bring your bird watching to a new level and implement a few tools that will help you track and process the data.
You have chosen to store the data as a list of integers. The first number in the list is the number of birds that visited your garden today, the second yesterday, and so on.
Implement the BirdCount.today/1 function. It should take a list of daily bird counts and return today's count. If the list is empty, it should return nil.
Implement the BirdCount.increment_day_count/1 function. It should take a list of daily bird counts and increment the today's count by 1. If the list is empty, return [1].
Implement the BirdCount.has_day_without_birds?/1 function. It should take a list of daily bird counts. It should return true if there was at least one day when no birds visited the garden, and false otherwise.
Implement the BirdCount.total/1 function. It should take a list of daily bird counts and return the total number that visited your garden since you started collecting the data.
Some days are busier than others. A busy day is one where five or more birds have visited your garden.
Implement the BirdCount.busy_days/1 function. It should take a list of daily bird counts and return the number of busy days.
https://exercism.org/tracks/elixir/exercises/bird-count
defmodule BirdCount do
def today([]), do: nil
def today(list) do
hd list
end
def increment_day_count([]), do: [1]
def increment_day_count(list) do
result = list
|> today
|> Kernel.+(1)
[result | tl list]
end
def has_day_without_birds?([]), do: false
def has_day_without_birds?([head | tail]) do
case head do
0 -> true
_ -> has_day_without_birds? tail
end
end
def total([]), do: 0
def total([head | tail]) do
head + total tail
end
def busy_days([]), do: 0
def busy_days([head | tail]) do
if head >= 5, do: 1 + busy_days(tail), else: busy_days(tail)
# if head >= 5 do
# 1 + busy_days tail
# else
# busy_days tail
# end
# cond do
# head >= 5 -> 1 + busy_days tail
# head < 5 -> busy_days tail
# end
end
end